<?php
/**
 * 分类列表 - JBlog
 * 
 * @copyright (c) 2008-2010 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id: cate.php 478 2010-06-07 03:40:39Z lisijie86 $
*/

!defined('IN_JBLOG') && exit('Access Denied!');

$cate = array();
if ( isset($get['id']) ) {
	$get['id'] = intval($get['id']);
	$cate = $_CACHE['cate'][$get['id']];
} elseif ( isset($get['alias']) )  {
	foreach ( $_CACHE['cate'] as $row ) {
		if ( $row['alias'] == $get['alias'] ) {
			$cate = $row;
			break;
		} 
	}
}
if ( !$cate ) {
	error_404();
}
if ( $cate['redirect'] ) {
	redirect($cate['redirect']);
}
if ( $cate['children'] > 0 ) {
	$cids = array();
	foreach ( $_CACHE['cate']['blog'] AS $val ) {
		if ( $_CACHE['cate'][$val]['parentid'] == $cate['id']  ) {
			$cids[] = $val;
		}
	}
} else {
	$cids = array($cate['id']);
}

$page = max(1, intval($get['page']));
$pagesize = config('pagesize');
$offset = ($page - 1) * $pagesize;
$count = $db->count('post', "cateid IN (".simplode($cids).") AND `type` = 'blog' AND `status` = '1'");
$url = 'mod=cate&id='.$cate['id'].'&alias='.$cate['alias'];

query_post('blog', $offset, $pagesize, "cateid IN (".simplode($cids).")");

blog('title', $cate['catename']);
blog('keywords', $cate['keywords']);
blog('description', $cate['description']);

if ( is_file(THEME_ROOT.'cate.php') ) {
	template('cate');
} else {
	template('list');
}
?>